#******************************************************************
#
# Copyright 2015 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

##
# NotificationManager build script
##

Import('env')

lib_env = env.Clone()
SConscript('#service/third_party_libs.scons', 'lib_env')
scenemanager_env = lib_env.Clone()

target_os = env.get('TARGET_OS')

if scenemanager_env.get('RELEASE'):
    scenemanager_env.AppendUnique(CCFLAGS=['-Os'])
else:
    scenemanager_env.AppendUnique(CCFLAGS=['-g'])
######################################################################
# Build flags
######################################################################
scenemanager_env.AppendUnique(CPPPATH=[
    './include',
    './src',
    '#/resource/csdk/connectivity/api',
    '../resource-encapsulation/include',
    '../resource-encapsulation/src/common/primitiveResource/include',
    '../resource-encapsulation/src/common/expiryTimer/include',
    '#/resource/c_common',
    '#/resource/c_common/oic_malloc/include',
    '#/resource/c_common/oic_string/include',
    '#/resource/csdk/include',
    '#/resource/csdk/stack/include',
    '#/resource/include',
    '#/resource/oc_logger/include'
])

scenemanager_env.PrependUnique(LIBS=[
    'coap',
    'connectivity_abstraction',
    'oc_logger',
    'octbstack',
    'oc',
    'rcs_client',
    'rcs_server',
    'rcs_common',
])

if target_os not in ['windows']:
    scenemanager_env.AppendUnique(
        CXXFLAGS=['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])

if target_os not in ['darwin', 'ios', 'windows']:
    scenemanager_env.AppendUnique(LINKFLAGS=['-Wl,--no-undefined'])

if target_os in ['linux']:
    scenemanager_env.AppendUnique(LIBS=['pthread'])

if target_os == 'android':
    scenemanager_env.AppendUnique(CXXFLAGS=['-frtti', '-fexceptions'])
    scenemanager_env.AppendUnique(LIBS=['gnustl_shared', 'log'])

######################################################################
# Source files and Targets
######################################################################
SCENE_SRC_DIR = './src/'
scenemanager_src = Glob(SCENE_SRC_DIR + '*.cpp')

if target_os in ['tizen', 'android']:
    scenemanagersdk = scenemanager_env.SharedLibrary('scene_manager',
                                                     scenemanager_src)
else:
    scenemanagersdk = scenemanager_env.StaticLibrary('scene_manager',
                                                     scenemanager_src)

scenemanager_env.InstallTarget(scenemanagersdk, 'libscene_manager')
scenemanager_env.UserInstallTargetLib(scenemanagersdk, 'libscene_manager')
scenemanager_env.UserInstallTargetHeader(
    'include/SceneList.h', 'service/scene-manager', 'SceneList.h')
scenemanager_env.UserInstallTargetHeader(
    'include/SceneCollection.h', 'service/scene-manager', 'SceneCollection.h')
scenemanager_env.UserInstallTargetHeader('include/Scene.h',
                                         'service/scene-manager', 'Scene.h')
scenemanager_env.UserInstallTargetHeader(
    'include/SceneAction.h', 'service/scene-manager', 'SceneAction.h')
scenemanager_env.UserInstallTargetHeader(
    'include/RemoteSceneList.h', 'service/scene-manager', 'RemoteSceneList.h')
scenemanager_env.UserInstallTargetHeader('include/RemoteSceneCollection.h',
                                         'service/scene-manager',
                                         'RemoteSceneCollection.h')
scenemanager_env.UserInstallTargetHeader(
    'include/RemoteScene.h', 'service/scene-manager', 'RemoteScene.h')
scenemanager_env.UserInstallTargetHeader('include/RemoteSceneAction.h',
                                         'service/scene-manager',
                                         'RemoteSceneAction.h')

# Go to build Unit test
if scenemanager_env.get('WITH_TEST') and target_os in ('linux'):
    SConscript('unittests/SConscript')

# Go to build sample apps
SConscript('sampleapp/SConscript')
